#include "myserver.h"
#include "mythread.h"
#include <QDebug>

MyServer::MyServer(QObject *parent)
    : QTcpServer(parent)
{

}

void MyServer::startServer()
{
    int port = 1234;
    if (this->listen(QHostAddress::Any, port)){
        qDebug() << "Listening port " << port << " ...";
    }else{
        qDebug() << "Could not start server.";
    }
}

MyServer::~MyServer()
{

}

void MyServer::incomingConnection(qintptr handle)
{
    // We have a new connection
    qDebug() << handle << " Connecting...";

    MyThread *thread = new MyThread(handle, this);

    // Every new connection will be run in a newly created thread
    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));

    thread->start();
}

